Skip to content

Computer Graphics - Viewing Transformation include the following topics: View / Camera Transformation and Projection Transformation.


CG-Viewing Transformation

View Transformation

sEmyaO

  • Define the camera first
    • Position e
    • Look-at / gaze direction g
    • Up direction t^ (assuming perpendicular to look-at)

Key observation

If the camera and all objects move together, the “photo” will be the same.

mfynva

How about that we always transform the camera to

  • The origin, up at Y, look at Z
  • And transform the objects along with the camera

RdtATY

  • Mview in math?

    • Translates e to origin
    • Rotates g to Z
    • Rotates t to Y
    • Rotates (g×t) to X
    • Difficult to write!
  • Mview in math?

    • Let's write Mview=RviewTview
      • Translate e to origin:
        Tview=[100xe010ye001ze0001]
      • Rotate g to Z, t to Y, (g×t^) to X
    • Consider its inverse rotation: X(g×t^),Yt^,Zg
Rview1=[xg^×t^xt^xg0yg^×t^yt^yg0zg^×t^zt^zg00001]Rview=[xg^×t^yg^×t^zg^×t^0xt^yt^zt^0xgygzg00001]

Also Known as ModelView Transformation

Projection Transformation

2Tppp5

Orthographic Projection

  • A simple way of understanding

    • Camera located at origin, looking at Z, up at Y
    • Drop Z coordinate
    • Translate and scale the resulting rectangle to [1,1]2
  • In general

    • We want to map a cuboid [l,r]×[b,t]×[f,n]
      to the "canonical" (正则, 规范, 标准) cube [1,1]3.

MYF0T2

  • Transformation matrix

    • Translate (center to origin) first, then scale (length/width/height to 2)
    Mortho=[2rl00002tb00002nf00001][100r+l2010t+b2001n+f20001]

Perspective Projection

  • How to do perspective projection
    • First "squish" the frustum into a cuboid (nn,ff) (Mpersportho)
    • Do orthographic projection (Mortho, already known!)

0fL3IX

  • In order to find a transformation

    • Find the relationship between transformed points (x,y,z)
      and the original points (x,y,z):
    y=nzyx=nzx (similar to y)

mKkiAs

  • In homogeneous coordinates,
(xyz1)(nxznyzunknown1)(mult. by z)==(nxnystill unknownz)
  • So the "squish" (persp to ortho) projection does this
Mpersportho(4×4)(xyz1)=(nxnyunknownz)
  • Already good enough to figure out part of Mpersportho:
Mpersportho=(n0000n00????0010)
  • Observation: the third row is responsible for z

    • Any point on the near plane will not change
    • Any point’s z on the far plane will not change
  • Any point on the near plane will not change

Mpersportho(4×4)(xyz1)=(nxnyunknownz)(replace z with n)(xyn1)(xyn1)=(nxnyn2n)
  • So the third row must be of the form (00AB)
(00AB)(xyn1)=n2n2 has nothing to do with x and y
  • Any point’s z on the far plane will not change
(00f1)(00f1)=(00f2f)Af+B=f2
  • Solve for A and B:
An+B=n2Af+B=f2A=n+f,B=nf
  • Finally, every entry in Mpersportho is known!
Mpersportho=(n0000n0000n+fnf0010)
  • What’s next?
    • Perform orthographic projection (Mortho) to finish.
    • Combine transformations:Mpersp=MorthoMpersportho

Vertical field-of-view (fovY)

I2FFJe

How to convert from fovY and aspect to l,r,b,t?

ANPsS1